# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     state
   Description :
   Author :       Flyoung
   date：          2023/3/16
-------------------------------------------------
   Change Activity:
                   2023/3/16:
-------------------------------------------------
"""
from typing import AnyStr


class State:
    def __init__(self, tag: AnyStr):
        self.tag = tag
        self.next_states = list()

    def add_next_state(self, edge: AnyStr, state: 'State'):
        self.next_states.append((edge, state))
        return state

    def __repr__(self):
        return self.tag

    def move(self, target):
        for edge, state in self.next_states:
            if edge == target:
                return state
        return None

    def __lt__(self, other: 'State'):
        return self.tag < other.tag

    def __eq__(self, other):
        if isinstance(other, str):
            return self.tag == other
        return self.tag == other.tag

    def __hash__(self):
        return hash(self.tag)


class StateDistributor:
    def __init__(self, n: int = 100):
        self.idx = 0
        self.states = [State(str(i)) for i in range(n + 1)]

    def apply_state(self):
        s = self.states[self.idx]
        self.idx += 1
        return s
